<template>
  <div class="com-container">
    <div class="com-chart" ref="year_ref"></div>
  </div>
</template>

<script>
export default {
  name: 'FYYear',
  data () {
    return {
      chart: null
    }
  },
  destroyed () {
    window.removeEventListener('resize', this.updateChart)
  },
  mounted () {
    this.chart = this.$echarts.init(this.$el, null, {
      renderer: 'canvas'
    })
    this.updateChart()
    window.addEventListener('resize', this.updateChart)
  },
  methods: {
    updateChart () {
      const option = {
        backgroundColor: 'transparent',
        title: {
          text: '非遗项目入选年份分布',
          subtext: '数据来源：中国非物质文化遗产网',
          left: 'center',
          top: 10,
          textStyle: {
            color: '#4A2F1D',
            fontSize: 18,
            fontWeight: 'bold'
          },
          subtextStyle: {
            color: '#6B4423',
            fontSize: 12
          }
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          },
          backgroundColor: 'rgba(255, 255, 255, 0.95)',
          borderColor: '#E8D5C4',
          borderWidth: 1,
          textStyle: {
            color: '#4A2F1D'
          }
        },
        legend: {
          data: ['人类非物质文化遗产代表作名录', '急需保护的非物质文化遗产名录', '优秀实践名册'],
          top: 50,
          textStyle: {
            color: '#4A2F1D',
            fontSize: 12
          }
        },
        grid: {
          left: '5%',
          right: '5%',
          bottom: '10%',
          top: '25%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          data: ['2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023'],
          axisLabel: {
            color: '#4A2F1D',
            fontSize: 12,
            interval: 0,
            rotate: 45
          },
          axisLine: {
            lineStyle: {
              color: '#E8D5C4'
            }
          }
        },
        yAxis: {
          type: 'value',
          name: '项目数量',
          nameTextStyle: {
            color: '#4A2F1D',
            fontSize: 12,
            padding: [0, 0, 0, 30]
          },
          axisLabel: {
            color: '#4A2F1D',
            fontSize: 12
          },
          splitLine: {
            lineStyle: {
              color: 'rgba(232, 213, 196, 0.3)'
            }
          },
          axisLine: {
            lineStyle: {
              color: '#E8D5C4'
            }
          }
        },
        series: [
          {
            name: '人类非物质文化遗产代表作名录',
            type: 'bar',
            stack: 'total',
            barWidth: '60%',
            itemStyle: {
              color: '#E8D5C4'
            },
            emphasis: {
              itemStyle: {
                color: '#DDB892'
              }
            },
            data: [28, 22, 16, 12, 10, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1]
          },
          {
            name: '急需保护的非物质文化遗产名录',
            type: 'bar',
            stack: 'total',
            itemStyle: {
              color: '#DDB892'
            },
            emphasis: {
              itemStyle: {
                color: '#B08968'
              }
            },
            data: [7, 6, 5, 4, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1]
          },
          {
            name: '优秀实践名册',
            type: 'bar',
            stack: 'total',
            itemStyle: {
              color: '#B08968'
            },
            emphasis: {
              itemStyle: {
                color: '#7F5539'
              }
            },
            data: [4, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
          }
        ]
      }
      this.chart.setOption(option)
      this.chart.resize()
    }
  },
  beforeDestroy() {
    if (this.chart) {
      this.chart.dispose()
    }
  }
}
</script>

<style>
</style> 